package com.weichen.studentgameexchange.game.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weichen.studentgameexchange.game.common.Result;
import com.weichen.studentgameexchange.game.entity.UserGameCollection;
import com.weichen.studentgameexchange.game.entity.UserGameGrade;
import com.weichen.studentgameexchange.game.entity.vo.CollectionVo;
import com.weichen.studentgameexchange.game.service.IUserGameCollectionService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 惟尘
 * @since 2025-02-01
 */
@RestController
@RequestMapping("/game/userGameCollection")
public class UserGameCollectionController {


    @Autowired
    IUserGameCollectionService userGameCollectionService;


/**
 * TODO 用户-游戏--游戏收藏
 */
    /**
     * 用户添加或删除游戏收藏
     * @param userGameCollection
     * @return
     */
    @Operation(summary = "用户添加或删除游戏收藏接口")
    @PostMapping("/user/addOrdelete")
    public Result userAddorDelete(@RequestBody UserGameCollection userGameCollection){
        return userGameCollectionService.userAddorDelete(userGameCollection);
    }

    /**
     * 用户查看游戏收藏
     * @param userId
     * @param gameId
     * @return
     */
    @Operation(summary = "用户查看游戏收藏接口")
    @GetMapping("/user/select")
    public Result userSelect(@RequestParam("userId") Long userId,@RequestParam("gameId") Long gameId){
        return userGameCollectionService.userSelect(userId,gameId);
    }

    /**
     * 用户查看所有游戏收藏接口
     * @param userId
     * @return
     */
    @Operation(summary = "用户查看所有游戏收藏接口")
    @GetMapping("/user/select/{userId}")
    public Result userSelectById(@PathVariable("userId") Long userId){
        return userGameCollectionService.userSelectById(userId);
    }



/**
 * TODO 管理员-游戏--游戏收藏管理
 */
    /**
     * 管理员分页查询收藏信息
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "管理员分页查询收藏信息接口")
    @GetMapping("/admin/page")
    public Result adminPage(@RequestParam(value = "page",defaultValue = "1") Integer page,
                            @RequestParam(value = "size",defaultValue = "5") Integer size){
        Page<CollectionVo> collectionVoPage = userGameCollectionService.adminPage(page, size);
        return Result.success(collectionVoPage);
    }

    /**
     * 管理员删除单个游戏收藏
     * @param collectionId
     * @return
     */
    @Operation(summary = "管理员删除单个游戏收藏接口")
    @DeleteMapping("/admin/delete/{collectionId}")
    public Result adminDeleteOne(@PathVariable("collectionId") Long collectionId){
        userGameCollectionService.removeById(collectionId);
        return Result.success();
    }

    /**
     * 管理员批量删除多个游戏收藏
     * @param collectionIds
     * @return
     */
    @Operation(summary = "管理员批量删除多个游戏收藏接口")
    @DeleteMapping("/admin/delete/batch")
    public Result adminDeleteBatch(@RequestBody List<Long> collectionIds){
        userGameCollectionService.removeBatchByIds(collectionIds);
        return Result.success();
    }
}
